<template>
	<view :class="['page',{'iphoneX':isIphoneX}]">
		<template v-if="isLogin">
			<view class="body">
				<view class="form-wrap m-b2">
					<view class="form-item">
						<view class="label">项目名称：</view>
						<view class="form-input">
							<view class="content">
								<input type="text" class="inp" v-model="params.pname" placeholder="输入项目名称" />
							</view>
						</view>
					</view>

					<view class="form-item">
						<view class="label">项目编号：</view>
						<view class="form-input">
							<view class="content">
								<input type="text" class="inp" v-model="params.number" placeholder="输入项目编号" />
							</view>
						</view>
					</view>

					<view class="form-item">
						<view class="label">项目地址：</view>
						<view class="form-input">
							<view class="content">
								<input type="text" class="inp" v-model="params.address" placeholder="输入项目地址" />
							</view>
						</view>
					</view>

					<view class="form-item">
						<view class="label">项目类型：</view>
						<picker class="form-picker" mode="selector" :range="type" range-key="name"
							@change="changeTypes">
							<view class="picker">
								<input type="text" class="select-data t-l" v-model="params.project_type_name"
									placeholder="选择项目类型" disabled>
								<view class="icon">
									<view class="iconfont f-s68">&#xeb8a;</view>
								</view>
							</view>
						</picker>
					</view>

					<view class="form-item">
						<view class="label">实施单位：</view>
						<view class="form-input">
							<view class="content">
								<input type="text" class="inp" v-model="params.construction_uni" placeholder="输入实施单位" />
							</view>
						</view>
					</view>

					<view class="form-item">
						<view class="label">实施单位简称：</view>
						<view class="form-input">
							<view class="content">
								<input type="text" class="inp" v-model="params.company_shorter_form"
									placeholder="输入实施单位简称" />
							</view>
						</view>
					</view>

					<view class="form-textarea-item">
						<view class="label a-t">项目备注</view>
						<view class="form-textarea">
							<textarea class="inp-textarea" v-model="params.remarks" placeholder="输入项目备注"
								maxlength="-1"></textarea>
						</view>
					</view>

				</view>

			</view>

			<!-- 底部 -->
			<view class="footer">
				<view class="fix-wrap bottom">
					<view class="btn" @click="addProject">确定添加</view>
				</view>
			</view>


		</template>
	</view>
</template>

<script>
	import {
		dateFormat,
		uploadImage,
		previewImage,
		uploadToServe
	} from '@/common/util.js'
	export default {
		name: 'name',
		data() {
			return {
				page: '2', //  1 添加药剂   3 药剂分配  4 添加分配单位   
				isLogin: true,
				isIphoneX: getApp().globalData.isIphoneX,
				userInfo: uni.getStorageSync('userInfo'),
				isShowPrevData: false,
				isStop: true,
				allSpecs: {},
				type: [{
						id: 1,
						name: '防控'
					},
					{
						id: 2,
						name: '监测'
					},
					{
						id: 3,
						name: '监理'
					},
				],
				params: {
					pname: '',
					number: '',
					address: '',
					project_type: '1',
					project_type_name: '防控',
					construction_uni: '',
					company_shorter_form: '',
					remarks: '',
				},
				flag: {
					isFullPage: false,
					isShowSpec: false
				}
			}


		},
		async onLoad(params) {
			this.isLogin = await this.$loginState('check');
			if (this.isLogin) {

			}
		},
		async onShow() {

		},
		methods: {

			// 选择剂型
			changeTypes: function(e) {
				let idx = e.detail.value;
				this.params.project_type_name = this.type[idx].name;
				this.params.project_type = this.type[idx].id;
			},



			// 添加项目
			addProject: async function() {
				let _this = this;
				if (this.params.pname == '') {
					uni.showToast({
						icon: 'none',
						title: '请输入项目名称',
						mask: true,
						duration: 1000
					})
					return
				} 
				if (this.params.project_type_name == '') {
					uni.showToast({
						icon: 'none',
						title: '请选择项目类型',
						mask: true,
						duration: 1000
					})
					return
				}   
				
				uni.showLoading({
					title: "数据提交中..."
				})

				if (this.isStop) {
					this.isStop = false;
					let res = await this.$api.user_api.addMyMember({
						pname: this.params.pname,
						number: this.params.number,
						address: this.params.address,
						project_type: this.params.project_type,
						construction_uni: this.params.construction_uni,
						company_shorter_form: this.params.company_shorter_form,
						remarks: this.params.remarks,
						create_uid: this.userInfo.id,
					}) 

					if (res.data.ret == 0) {
						uni.hideLoading(); 
						uni.showToast({
							icon: 'success',
							title: '创建成功',
							mask: true,
							duration: 2000,
							success() {
								setTimeout(() => {
									_this.isStop = true;
									uni.navigateBack({
										delta: 1
									})
								}, 2000)
							}
						})
					} else {
						uni.hideLoading();
						uni.showToast({
							icon: 'none',
							image: '../../static/image/error.png',
							title: '上传失败',
							mask: true,
							duration: 2000,
							success() {
								setTimeout(() => {
									_this.isStop = true;
								}, 2000)
							}
						})
					}
				}


			}, 

		},
		components: {},

		 

	}
</script>

<style lang="less">
	.form-wrap .label {
		width: 35%;
	}

	.form-wrap .content .link {
		color: #000;
	}

	.status {
		padding: 0 20rpx;
		color: #f00;
		font-size: 28rpx;
	}

	.btn {
		@h: 80rpx;
		width: 98%;
		margin: 10rpx auto;
		text-align: center;
		height: @h;
		line-height: @h;
		background: linear-gradient(#e96b5c, #ce3c2f);
		border-radius: 10rpx;
		color: #fff;
		font-size: 34rpx;
	}
</style>
